package review.workspace;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.LinkedList;

public class test11 {

    public class treeNode{
        String st;
        ArrayList<treeNode> son;
        treeNode(String input){
            st = input;
        }
    }

    public treeNode buildTree(){
        treeNode head = new treeNode("p");
        head.son = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            treeNode t = new treeNode(String.valueOf(i));
            head.son.add(t);
        }
        return head;
    }
    public void help(treeNode root){
        if(root.son==null){
            return;
        }
        System.out.println(root.st);
        for (int i = 0; i < root.son.size(); i++) {
            treeNode temp = root.son.get(i);
            System.out.println(temp.st);
            help(temp);
        }
    }

    public void cen(treeNode root){
        Deque<treeNode> queue = new ArrayDeque<>();
        queue.push(root);

        while(!queue.isEmpty()){
            treeNode node = queue.pollFirst();
            if(node.son==null){
                break;
            }
            for (int i = 0; i < node.son.size(); i++) {
                queue.push(node.son.get(i));
                System.out.println(node.son.get(i).st);
            }
        }
    }


    public static void main(String[] args) {
        test11 test11 = new test11();
        treeNode node = test11.buildTree();
        test11.cen(node);

    }




}
